package pearson.automation.forms.courseDetails;

import org.openqa.selenium.By;

import pearson.automation.forms.courseDetails.AddCollaborators.AccessRights;

import framework.BaseForm;
import framework.elements.Button;
import framework.elements.ComboBox;
import framework.elements.Label;
/**
 * 
 *  Form for collaborators operations. Location:
 * CourseForm->Collaborators->Edit
 *
 */
public class EditCollaborators extends BaseForm {

    private static Label identifyer  = new Label(By.xpath("//h2[contains(text(),'Edit')]"), "Edit collaborators");
    private String removeXPathTemplate = "//div/span[text()='%1$s']/..//label[text()='Remove']";
    private String editRightsXpathTemplate = "//div/span[text()='%1$s']/../select";
    private Button submit = new Button(By.cssSelector("input[value='Send Request']"), "Send Request");
    
    
    public EditCollaborators() {
    super(identifyer.getLocator(), identifyer.getName());
    }
    
    public CollaboratorsForm removeCollaborator(String collaboratorName) {
    Button remove = new Button(By.xpath(String.format(removeXPathTemplate, collaboratorName)), collaboratorName);
    remove.click();
    submit.clickAndWait();
    return new CollaboratorsForm();
    }
    
    public CollaboratorsForm changeRights(String collaboratorName, AccessRights access) {
    ComboBox rights = new ComboBox(By.xpath(String.format(editRightsXpathTemplate, collaboratorName)), "Access Rights");
    rights.selectByValue(access.toString());
    submit.clickAndWait();
    return new CollaboratorsForm();
    }
}
